/**************************
* @Summary
* @Author 20009200303 赵传博
* @Date 2022/3/31
*****************************/

#include "Tree.h"

void insertNode(string word, Tnode* root){
    auto* node = new Tnode;
    node->count = 1;
    node->word = word;
    node->left = nullptr;
    node->right = nullptr;
    if(!root){
        root = node;
        return;
    }else if(root->word == word){
        ++root->count;
        delete node;
        return;
    }else if(root->word.compare(word) > 0){
        if(!root->left){
            root->left = node;
            return;
        }else{
            delete node;
            insertNode(word, root->left);
        }
    }else if(root->word.compare(word) < 0){
        if(!root->right){
            root->right = node;
            return;
        }else{
            delete node;
            insertNode(word, root->right);
        }
    }else{
        cout << "Error" << endl;
    }
}
void printTrees(Tnode* root){
    if(!root) return;
    cout << root->word << "(" << root->count << ")" << " ";
    if(root->left) printTrees(root->left);
    if(root->right) printTrees(root->right);
}
void printTreesInOrder(Tnode* root){
    if(!root) return;
    if(root->left) printTreesInOrder(root->left);
    cout << root->word << "(" << root->count << ")" << " ";
    if(root->right) printTreesInOrder(root->right);
}